
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Entity;

namespace Data
{
	public class DAPlanAdmision
	{
	      
        public static DataTable ListarPlanesAdmision()
        {
            SqlDatabase sqlPlanAdmision = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlPlanAdmision.GetStoredProcCommand("plst_PlanesAdmision");
            return sqlPlanAdmision.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static DataSet ObtenerPlanAdmisionVigente()
		{
			SqlDatabase sqlPlanAdmision = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlPlanAdmision.GetStoredProcCommand("pdet_PlanAdmisionVigente");
            return sqlPlanAdmision.ExecuteDataSet(dbCmd);
		}

        public static DataSet ObtenerPlanAdmision(string strCodPlanAdmision)
        {
            SqlDatabase sqlPlanAdmision = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlPlanAdmision.GetStoredProcCommand("pdet_PlanAdmision");
            sqlPlanAdmision.AddInParameter(dbCmd, "@strCodPlanAdmision", DbType.String, strCodPlanAdmision);
            return sqlPlanAdmision.ExecuteDataSet(dbCmd);
        }

        public static void RegistrarPlanAdmision(BEPlanAdmision oBEPlanAdmision)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);

            using (DbConnection connection = sqlClient.CreateConnection())
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();
                try
                {
                    DbCommand dbCmd = sqlClient.GetStoredProcCommand("pins_PlanAdmision");
                    sqlClient.AddInParameter(dbCmd, "@Usuario", DbType.String, oBEPlanAdmision.UsuCreacion);
                    sqlClient.ExecuteNonQuery(dbCmd);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }

	}
}
      